package Algorithm.LinkedListProblem;

/**
 * @Author cj
 * @Date 2021/11/20 11:33
 */
public class removeMidNode {

    class Node {
        public int value;
        public Node next;

        public Node(int val) {
            this.value = val;
        }
    }

    public static Node removeMidNode1(Node head) {
        if (head == null || head.next == null) {
            return head;
        }
        if (head.next.next == null) { //只有两个节点
            // 删除第一个
            return head.next;
        }
        Node pre = head;
        Node cur = head.next.next;
        while (cur.next != null && cur.next.next != null) {
            cur = cur.next.next;
            pre = pre.next;
        }
        // 删除
        pre.next = pre.next.next;
        return head;
    }
}
